package top.itmeans.yes.search.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author Yiming.Cao
 */
@Configuration
@EnableTransactionManagement
@MapperScan({"top.itmeans.yes.mapper","top.itmeans.yes.search.mapper"})
public class MyBatisPlusConfig {
    /**
     * MybatisPlusInterceptor配置
     * --------------------------------------------
     * 使用多个功能需要注意顺序关系,建议使用如下顺序
     * 多租户,动态表名
     * 分页,乐观锁
     * sql 性能规范,防止全表更新与删除
     * 总结: 对sql进行单次改造的 优先放入, 不对sql进行改造的 最后放入
     * @return MybatisPlusInterceptor
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
